package com.example.takeaway.api;

import com.example.takeaway.common.R;
import com.example.takeaway.model.PageVO;
import com.example.takeaway.model.dto.SpecificationDTO;
import com.example.takeaway.model.dto.SpecificationEditorDTO;
import com.example.takeaway.model.vo.CategoryVO;
import com.example.takeaway.model.vo.SpecificationVO;
import com.example.takeaway.service.SpecificationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 规格表 前端控制器
 * </p>
 *
 * @author 邢晨旭
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/specification")
public class SpecificationApi {

    @Resource
    SpecificationService service;

    @PostMapping
    public R<Void> add(@RequestBody SpecificationDTO param) {
        service.addSpecification(param);
        return R.ok();
    }

    @PutMapping
    public R<Void> update(@RequestBody SpecificationEditorDTO param) {
        service.updateSpecificationById(param);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R<SpecificationVO> get(@PathVariable Long id) {
        return R.ok(service.queryById(id));
    }

    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) {
        service.deleteById(id);
        return R.ok();
    }

    @GetMapping("/page")
    public R<PageVO<SpecificationVO>> get(@RequestParam Integer page, @RequestParam Integer size) {
        return R.ok(service.queryPage(page,size));
    }

    @GetMapping("/list")
    public R<List<SpecificationVO>> get() {
        return R.ok(service.queryList());
    }

}
